from django.core.management.base import BaseCommand
from apps.oaauth.models import OAUser, OADepartment


class Command(BaseCommand):
    def handle(self, *args, **options):
        boarder = OADepartment.objects.get(name='董事会')
        developer = OADepartment.objects.get(name='产品开发部')
        operator = OADepartment.objects.get(name='运营部')
        saler = OADepartment.objects.get(name='销售部')
        hr = OADepartment.objects.get(name='人事部')
        finance = OADepartment.objects.get(name='财务部')
        GH = OAUser.objects.create_superuser(email='19517112363@163.com', realname='顾皓', password='123456',
                                             department=boarder)
        Howard = OAUser.objects.create_superuser(email='guhaorain@163.com', realname='顾皓', password='123456',
                                                 department=boarder)
        zhangsan = OAUser.objects.create_user(email='zhangsan@163.com', realname='张三', password='123456',
                                              department=developer)
        lise = OAUser.objects.create_user(email='lise@163.com', realname='李四', password='123456',
                                          department=operator)
        wangwu = OAUser.objects.create_user(email='wangwu@163.com', realname='王五', password='123456',
                                            department=hr)
        zhaoliu = OAUser.objects.create_user(email='zhaoliu@163.com', realname='赵六', password='123456',
                                             department=finance)
        sunqi = OAUser.objects.create_user(email='sunqi@163.com', realname='孙七', password='123456',
                                           department=saler)

        # 董事会
        boarder.leader = GH
        boarder.manager = None
        # 产品开发部
        developer.leader = zhangsan
        developer.manager = GH
        # 运营部
        operator.leader = lise
        operator.manager = GH
        # 人事部
        hr.leader = wangwu
        hr.manager = GH
        # 财务部
        finance.leader = zhaoliu
        finance.manager = Howard
        # 销售部
        saler.leader = sunqi
        saler.manager = Howard

        # 保存
        boarder.save()
        developer.save()
        operator.save()
        hr.save()
        finance.save()
        saler.save()

        self.stdout.write('初始用户创建成功！')